import { getsn } from "@/utils/getsn"
import { UserInfo, CallNet } from "@/utils/public";

/**
 * 数据库添加数据（保存）
 *
 * @export
 * @param {*} tableName 表名
 * @param {*} tmpList 数组 -> 表中的字段[{name:''123}]
 * @param {*} callback 回掉函数
 */
export function sqlEntryInsert(tableName, tmpList, callback) {
  AndroidApi.insert(JSON.stringify({
    "jToken": "",
    "tableName": tableName,
    "contentValues": tmpList
  }), function (msg) {
    callback("sqlInsert", msg);
  });
}
/**
 * 修改数据库字段
 *
 * @export
 * @param {*} tableName
 * @param {*} m_cid
 * @param {*} cons_no
 */
export function sqlEntryUpdata(tableName, m_cid, contentValues, callback) {
  AndroidApi.update(JSON.stringify({
    tableName: tableName,
    whereClause: "M_CID = ?",
    whereArgs: [m_cid],
    contentValues: contentValues
  }), function (msg) {
    callback("sqlUpdata", msg);
  });
}
/**
 * 
 *
 * @export
 * @param {*} tableName 表名
 * @param {*} FILE_ID 
 * @param {*} callback 
 */
export function sqlEntryDelete(tableName, m_cid, callback) {
  let delPhoto = {
    "tableName": tableName,
    "whereClause": "M_CID=?",
    "whereArgs": [m_cid]
  }
  AndroidApi.deletes(JSON.stringify(delPhoto), function (msg) {
    console.log("SC_RST_DTL_Table删除记录:" + JSON.stringify(msg))
    // AndroidApi.alert(JSON.stringify(msg));
    callback("sqlFILE_Delete", msg);
  });
}

/**
 *
 *
 * @export
 * @param {*} param
 * @param {*} SERVICE_ID
 * @param {*} callback
 */
export function submiEntryTremoval(param,SERVICE_ID, callback) {
  console.log({
    "data": {
      "SID": UserInfo.SID,
      "SN": getsn(),
      "DATA": {
        DUTY_ID: UserInfo.DUTY_ID,
        APP_NO: localStorage.getItem('APP_NO')?'':"0118082958554654",
        ...param
      },
      "SERVICE_ID": SERVICE_ID,
      "USER": UserInfo.USER,
      "PWD": UserInfo.PWD
    }
  });
  CallNet('', '',
    {
      "data": {
        "SID": UserInfo.SID,
        "SN": getsn(),
        "DATA": {
          DUTY_ID: UserInfo.DUTY_ID,
          APP_NO: localStorage.getItem('APP_NO')?'':"0118082958554654",
          TS_TYPE: '99',
          ...param
        },
        "SERVICE_ID": SERVICE_ID,
        "USER": UserInfo.USER,
        "PWD": UserInfo.PWD
      }
    },
    function (success) {
      console.log('提交', success);
      //回调
      callback(success);
    },
    function (error) {
      console.log('shibai', error);
      callback(error);
    }
  );
}